package com.kgc.service.Impl;

import com.kgc.dao.mapper.ArticlesMapper;
import com.kgc.entity.*;
import com.kgc.service.interf.ArticlesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

@Service("articlesService")
public class ArticlesServiceImpl implements ArticlesService {
    @Autowired
    private ArticlesMapper articlesMapper;
//   查询文章
    @Override
    public List<Articles> getAllArticle(String queryKey, String queryDateBegin, String queryDateEnd, Integer articleSort) {
        return articlesMapper.getAllArticle(queryKey,queryDateBegin, queryDateEnd,articleSort);
    }

    //查询草稿
    @Override
    public List<Articles> getdraft(int authorID) {
        return articlesMapper.getdraft(authorID);
    }

    //查询指定用户文章
    @Override
    public List<Articles> getArticleByUserID(int userID) {
        return articlesMapper.getArticleByUserID(userID);
    }

    //下拉框回显查询文章类别
    @Override
    public List<ArticleSort> getArticleType() {
        return articlesMapper.getArticleType();
    }
    // 发布文章
    @Override
    public int addArticle(Articles articles){
        return articlesMapper.addArticle(articles);
    }

    //删除指定用户下的指定文章
    @Override
    public int deleteArticle(Integer authorId,Integer articleId) {
        return articlesMapper.deleteArticle(authorId,articleId);
    }

    // 查询指定文章
    @Override
    public Articles getArticleByArticleID(int articleId) {
        return articlesMapper.getArticleByArticleID(articleId);
    }

    //修改文章
    @Override
    public int updateArticle(Articles article) {
        return articlesMapper.updateArticle(article);
    }


    // 查询文章收藏记录
    @Override
    public List<ArticleFavorites> getArticleFavorites(int userID,int articleID) {
        return articlesMapper.getArticleFavorites(userID,articleID);
    }

    //新增收藏记录
    @Override
    public int addArticleFavorites(ArticleFavorites articleFavorites) {
        return articlesMapper.addArticleFavorites(articleFavorites);
    }

    //修改收藏状态
    @Override
    public int updateFavoritesStatus(ArticleFavorites articleLikes1) {
        return articlesMapper.updateFavoritesStatus(articleLikes1);
    }

    //修改文章收藏量
    @Override
    public int updateFavoritesCount(int articleID,int p) {
        return articlesMapper.updateFavoritesCount(articleID,p);
    }

    //查询用户收藏文章
    @Override
    public List<Articles> getuserFavorites(int userID) {
        return articlesMapper.getuserFavorites(userID);
    }

    //增加文章浏览量
    @Override
    public int addarticlePageview(int articleID) {
        return articlesMapper.addarticlePageview(articleID);
    }

    //添加文章浏览记录
    @Override
    public int addarticleViews(int articleID, int userID) {
        Articleviews a=new Articleviews();
        a.setViewerID(userID);
        a.setArticleID(articleID);
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss ");
        a.setViewTimestamp(simpleDateFormat.format(new Date()));
        return articlesMapper.addarticleViews(a);
    }

    //查询文章点赞记录
    @Override
    public List<ArticleLikes> getArticleLikes(int userID, int articleID) {
        return articlesMapper.getArticleLikes(userID,articleID);
    }

    //添加点赞记录
    @Override
    public int addArticleLikes(ArticleLikes articleLikes) {
        return articlesMapper.addArticleLikes(articleLikes);
    }

    //修改点赞状态
    @Override
    public int updateLikesStatus(ArticleLikes articleLikes) {
        return articlesMapper.updateLikesStatus(articleLikes);
    }

    //修改点赞量
    @Override
    public int updateLikesCount(int articleID, int p) {
        return articlesMapper.updateLikesCount(articleID,p);
    }

    //    热门文章排序
    @Override
    public List<Articles> sort() {
        return articlesMapper.sort();
    }

//    获取当前用户对当前文章的点赞状态
    @Override
    public String getstatus1(Integer articleId, Integer userId) {
        return articlesMapper.getstatus1(articleId,userId);
    }
    //    获取当前用户对当前文章的收藏状态
    @Override
    public String getstatus2(Integer articleId, Integer userId) {
        return articlesMapper.getstatus2(articleId,userId);
    }

//    管理员修改文章类别库
    @Override
    public int updatesort(ArticleSort articleSort) {
        return articlesMapper.updatesort(articleSort);
    }
    //    管理员删除文章类别库
    @Override
    public int deletesort(ArticleSort articleSort) {
        return articlesMapper.deletesort( articleSort);
    }
    //    管理员新增文章类别库
    @Override
    public int addsort(ArticleSort articleSort) {
        return articlesMapper.addsort( articleSort);
    }

    //   管理员查询文章
    @Override
    public List<Articles> getAllArticle1(String queryKey, String queryDateBegin,
                                         String queryDateEnd, Integer articleSort,
                                         Integer articleID) {
        return articlesMapper.getAllArticle1(queryKey,queryDateBegin, queryDateEnd,articleSort, articleID);
    }

    //管理员上架下架文章
    @Override
    public int updateArticleStatus( String articleStatus,Integer articleID) {
        return articlesMapper.updateArticleStatus(articleStatus,articleID);
    }

    //管理员给个人用户发送通知
    @Override
    public int sendnotifications(Usernotifications usernotifications) {
        return articlesMapper.sendnotifications(usernotifications);
    }

    //用户查看个人通知
    @Override
    public List<Usernotifications> getnotifications(Integer userId) {
        return articlesMapper.getnotifications( userId);
    }

    //用户已读个人通知
    @Override
    public int readnotifications(Integer notificationsId) {
        return articlesMapper.readnotifications(notificationsId);
    }


}
